home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / Thread Manager / Sample Applications / 68k Examples / Dining Philos (THINK⁄MPW) / ProtoStructs.h < prev   
Encoding:
C/C++ Source or Header  |  1994-11-17  |  3.1 KB  |  146 lines  |  [TEXT/MPS ]

  1. /***********************************************************************************
  2. **
  3. ** I have tried to name all my functions in the following fashion: example_name, 
  4. ** yet_another_example, etc.
  5. ** 
  6. ** I did this to make sure that other folks who come in and read my code will be
  7. ** able to quickly discern betwen my functions and Toolbox calls just by looking
  8. ** at the naming convention.
  9. **
  10. ** My constants and globals are prepended by a k and g, respectively.
  11. */
  12.  
  13. #ifndef __THREADUTIL__
  14. #include <ThreadUtil.h>
  15. #endif
  16.  
  17. #ifndef __WINDOWS__
  18. #include <Windows.h>
  19. #endif
  20.  
  21. #ifndef __EVENTS__
  22. #include <Events.h>
  23. #endif
  24.  
  25. /***********************************************************************************
  26. **
  27. ** Constants.
  28. */
  29.  
  30. #define TRUE                    1
  31. #define    FALSE                    0
  32.  
  33. /* Philo stuff */
  34. #define    kNumOfPhilosophizers    5
  35. #define    kIconDimension            32
  36. #define    kIconOffset                15
  37. #define    kNumAllowedIn            kNumOfPhilosophizers - 1
  38. #define    kNumberOfIterations        2000
  39. #define    kThinkingTimeLimit        10
  40. #define    kEatingTimeLimit        10    
  41.  
  42. /* Fork state */
  43. #define    kNoForks                0
  44. #define    kLeftFork                1
  45. #define    kBothForks                2
  46.  
  47. /* Icon IDs */
  48. #define    kNoForkIcon                150
  49. #define    kLeftForkIcon            200
  50. #define    kBothForksIcon            250
  51.  
  52. /* Menu IDs */    
  53. #define    kAppleMenu                128
  54. #define    kFileMenu                129
  55.  
  56. /* Item IDs */
  57. #define    kAboutItem                1
  58. #define    kQuitItem                1
  59.  
  60. /* WNE parameter */
  61. #define    kSleepTicks             60
  62.  
  63. /* Error flags */
  64. #define    kFatal                    1
  65. #define    kNotFatal                0
  66.  
  67. /* Alert dialog stuff */
  68. #define    kAboutThisApp            200
  69. #define    kErrorAlert                129
  70.  
  71. #define kPictID                    128
  72.  
  73.  
  74. /***********************************************************************************
  75. **
  76. ** Structs
  77. */
  78.  
  79. typedef struct    {    /* Resource handles, where it is, does it have a fork */
  80.     Rect            thinking_location, waiting_location, dining_location;
  81.     Rect            current_location;
  82.     short            left_fork, fork_state;
  83.     ThreadID        theThread;
  84. } philoRecord, *philoPtr;
  85.  
  86.  
  87. /***********************************************************************************
  88. **
  89. ** Function Prototypes
  90. */
  91.  
  92. /*
  93. ** main.c
  94. */
  95. /* App utils */
  96. void system_attrib(void);
  97. void error(Str255, short, short);
  98. void cpy_pas_string(Str63 *, Str63);
  99. short is_DA_window(WindowPtr);
  100.  
  101. /* Init stuff */
  102. void init_mac(void);
  103. WindowPtr init_rooms(void);
  104. void init_philosophizers(WindowPtr);
  105. void init_threads(void);
  106.  
  107. /* Menus, events */
  108. void menu_command(long);
  109. void do_apple_menu(short);
  110. void event_loop(void);
  111. void keydown_evt(EventRecord);
  112. void mousedown_evt(EventRecord);
  113. void update_evt(EventRecord);
  114. void suspend_resume_evt(EventRecord);
  115.  
  116. /* Drawing */
  117. void draw_background(WindowPtr);
  118. void draw_philosophizers(WindowPtr);
  119. void draw_and_slam(WindowPtr);
  120.  
  121.  
  122.  
  123. /*
  124. ** threadstuff.c
  125. */
  126. /* Thread execution */
  127. void spawn_threads(void);
  128. pascal void *philo_actions(void *);
  129. void think_for_a_while();
  130. void go_to_eat(philoPtr);
  131. void eat_for_a_while(philoPtr);
  132. void go_to_think(philoPtr);
  133.  
  134. /* Forks */
  135. void create_forks(void);
  136. void pick_up_right_fork(philoPtr);
  137. void pick_up_left_fork(philoPtr);
  138. void put_down_right_fork(philoPtr);
  139. void put_down_left_fork(philoPtr);
  140. void remove_forks(void);
  141.  
  142. /* Footman */
  143. void create_footman(void);
  144. void checkin_with_footman(void);
  145. void checkout_with_footman(void);
  146. void retire_footman(void);